import 'package:flutter/material.dart';

void main() {
  // 1. 运行应用程序。
  runApp(const MaterialApp(
    home: Main(),
  ));
}

class Main extends StatelessWidget {
  const Main({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'GridView组件 - 1.基础用法',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.purple,
      ),
      body: Container(
        padding: const EdgeInsets.all(10),
        color: Colors.black12,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3, // 3 列
            mainAxisSpacing: 10, // 主轴间距
            crossAxisSpacing: 10, // 侧轴间距
            childAspectRatio: 100 / 50, // 宽高比
          ),
          children: [
            Container(
              color: Colors.red,
              alignment: Alignment.center,
              child: const Text('子项1'),
            ),
            Container(
              color: Colors.green,
              alignment: Alignment.center,
              child: const Text('子项2'),
            ),
            Container(
              color: Colors.blue,
              alignment: Alignment.center,
              child: const Text('子项3'),
            ),
            Container(
              color: Colors.orange,
              alignment: Alignment.center,
              child: const Text('子项4'),
            ),
            Container(
              color: Colors.yellow,
              alignment: Alignment.center,
              child: const Text('子项5'),
            ),
            Container(
              color: Colors.pink,
              alignment: Alignment.center,
              child: const Text('子项6'),
            ),
          ],
        ),
      ),
    );
  }
}
